﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;

/// <summary>
///GetBackPwdDAL 的摘要说明
/// </summary>
public class GetBackPwdDAL
{
    /// <summary>
    /// 根据参数返回绑定密码信息
    /// </summary>
    /// <param name="sign"></param>
    /// <param name="para"></param>
    /// <param name="question"></param>
    /// <returns></returns>
    public BakcPwd GetPwdByParam(int sign,string emcard, string para, string question)
    {
        SqlConnection con = null;
        SqlDataReader reader = null;
        try
        {
            Tools tool = new Tools();
            tool.AddSqlParameter("@sign", SqlDbType.Int, sign);
            tool.AddSqlParameter("@emcard", SqlDbType.VarChar, emcard);
            tool.AddSqlParameter("@para", SqlDbType.VarChar, para);
            tool.AddSqlParameter("@question", SqlDbType.VarChar, question);
            con = new SqlConnection(DBConn.Con_emweb_new);
            BakcPwd bpwd = null;
            using (reader = Emoney.DataAccess.SqlHelper.ExecuteReader(con, CommandType.StoredProcedure, "[dbo].[GetPwdByParam]", tool.GetSqlParameters()))
            {

                if (reader.Read())
                {
                    bpwd = new BakcPwd();
                    bpwd.Id = Tools.GetInt(reader["Id"]);
                    bpwd.EmCard = Tools.GetString(reader["emcard"]);
                    bpwd.Email = Tools.GetString(reader["email"]);
                    bpwd.Tel = Tools.GetString(reader["tel"]);
                    bpwd.Question = Tools.GetString(reader["question"]);
                    bpwd.Answer = Tools.GetString(reader["answer"]);
                }
            }
            return bpwd;
        }
        catch (Exception ex)
        {
            return null;
        }
    }
    /// <summary>
    /// 插入或修改绑定密码信息
    /// </summary>
    /// <param name="sign"></param>
    /// <param name="emcard"></param>
    /// <param name="empwd"></param>
    /// <param name="para"></param>
    /// <param name="question"></param>
    /// <returns></returns>
    public int InsertOrUpdateBack(int sign, string emcard,string guid, string para, string question) {
        int result = 0;
        try
        {
            Tools tool = new Tools();
            tool.AddSqlParameter("@sign", SqlDbType.Int, sign);
            tool.AddSqlParameter("@emcard", SqlDbType.VarChar, emcard);
            tool.AddSqlParameter("@guid", SqlDbType.VarChar, guid);
            tool.AddSqlParameter("@para", SqlDbType.VarChar, para);
            tool.AddSqlParameter("@question", SqlDbType.VarChar, question);
            result = Emoney.DataAccess.SqlHelper.ExecuteNonQuery(DBConn.Con_emweb_new, CommandType.StoredProcedure, "GbackPwdAddAndUpdate", tool.GetSqlParameters());
        }
        catch (Exception)
        {
            result = 0;
        }
        return result;
    }
}